﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Web.Administration;
using System.Diagnostics;
using System.Threading;
using System.Management;

namespace Xxf.IISM
{
    class Program
    {
        static void Main(string[] args)
        {

            //新建一个Stopwatch变量用来统计程序运行时间
            //Stopwatch watch = Stopwatch.StartNew();
            ////获取本机运行的所有进程ID和进程名,并输出哥进程所使用的工作集和私有工作集
            //foreach (Process ps in Process.GetProcesses())
            //{
            //    PerformanceCounter pf1 = new PerformanceCounter("Process", "Working Set - Private", ps.ProcessName);
            //    PerformanceCounter pf2 = new PerformanceCounter("Process", "Working Set", ps.ProcessName);
            //    Console.WriteLine("{0}:{1}  {2:N}KB", ps.ProcessName, "工作集(进程类)", ps.WorkingSet64 / 1024);
            //    Console.WriteLine("{0}:{1}  {2:N}KB", ps.ProcessName, "工作集        ", pf2.NextValue() / 1024);
            //    //私有工作集
            //    Console.WriteLine("{0}:{1}  {2:N}KB", ps.ProcessName, "私有工作集    ", pf1.NextValue() / 1024);

            //}

            //watch.Stop();
            Console.WriteLine(Computer.GetCpuCount());
            Console.WriteLine(Computer.GetCpuMHZ()[0]);
            Console.WriteLine(Computer.GetSizeOfDisk());
            Computer c = new Computer();
            Console.WriteLine(c.IpAddress+","+c.MacAddress); 

            Console.Read();
        }
        static void IIs()
        {
            ServerManager iisManager = new ServerManager();
            //iisManager.Sites.Add("NewSite", "http", "*:8080:", "E:\\work\\Xxf.IISM");
            //iisManager.CommitChanges();
            foreach (var item in iisManager.Sites)
            {
                Console.WriteLine("id:{0},name:{1},ServerAutoStart:{2},path:{3},LogFile.Directory:{4},ApplicationPoolName:{5},state:{6}", item.Id, item.Name, item.ServerAutoStart, item.Applications.Count, item.LogFile.Directory, item.ApplicationDefaults.ApplicationPoolName, item.State);
            }
            var t = iisManager.ApplicationPools["mvc"];
            foreach (var item in iisManager.ApplicationPools["mvc"].Attributes)
            {
                Console.WriteLine("name:{0},value:{1}", item.Name, item.Value);
            }
            foreach (var item in iisManager.ApplicationPools["mvc"].ChildElements)
            {
                Console.WriteLine("数量:{0},Name:{1}", item.Attributes.Count, item.Attributes.FirstOrDefault()?.Name);
            }
            //iisManager.ApplicationPools.Add("testPool");
        }

    }
}
